#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	int n;
	cin >> n;
	int i = 0;
	int sum = 0;
	while(i <= n)
	{
		if(i % 7 != 0 && i / 10 != 7 && i % 10 != 7)
			sum += pow(i,2);
		i++;
	}
	cout << sum << endl;
	return 0;
} 
